package com.jun.study.web;


import com.jun.study.entity.User;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.*;

/**
 * 描述:
 *
 * @outhor jun
 * @create 2018-04-02 15:58
 */
@RestController
public class HelloController {

    private final Logger logger = Logger.getLogger(getClass());

    @Autowired
    private DiscoveryClient client;


    @RequestMapping(value = "/hello" , method = RequestMethod.GET)
    public String index(){
        ServiceInstance instance = client.getLocalServiceInstance();
        logger.info("/hello , host : " + instance.getHost() + " , service_id : " + instance.getServiceId());
        return "Hello world";
    }

    @RequestMapping(value = "/hello1" , method = RequestMethod.GET)
    public String hello(@RequestParam String name){
        return "Hello" + name;
    }

    @RequestMapping(value = "/hello2" , method = RequestMethod.GET)
    public User hello(@RequestHeader String name , @RequestHeader Integer age){
        return new User(name , age);
    }

    @RequestMapping(value = "/hello3" , method = RequestMethod.POST)
    public String hello(@RequestBody User user){
        return "hello "+ user.getName() + ", " + user.getAge();
    }

}
